<template>
    <div>
      <el-table
        :data="tableData"
        border
        style="width: 100%">
        <el-table-column
          fixed
          prop="id"
          label="编号"
          width="150">
        </el-table-column>
        <el-table-column
          prop="name"
          label="姓名"
          width="120">
        </el-table-column>
        <el-table-column
          prop="author"
          label="作者"
          width="120">
        </el-table-column>
        <el-table-column
          label="操作"
          width="100">
          <template slot-scope="scope">
            <el-button @click="edit(scope.row)" type="text" size="small">修改</el-button>
            <el-button @click="deleteBook(scope.row)" type="text" size="small">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        layout="prev, pager, next"
        page-size="3"
        :total=total
        @current-change="page">    //@绑定事件 当且页切换触发page函数
      </el-pagination>
    </div>
</template>

<script>
  const axios = require('axios');
  export default {
    methods: {
      deleteBook(row){
        const _this = this
        axios.delete('http://localhost:9999/deleteById/'+row.id).then(function (resp) {
          _this.$alert(row.name+'删除成功', '恭喜你，成功了', {
            confirmButtonText: '确定',
            callback: action => {
              window.location.reload()
            }
          });
        })
      },
      edit(row){
        this.$router.push({
          path:'/update',
          query:{
            id:row.id
          }
        })
      },
      page(currentPage){
        // alert(currenctPage)   //打印当前页码
        const _this = this
        axios.get('http://localhost:9999/findAll/'+currentPage+'/3').then(
          function (resp) {
            _this.tableData = resp.data.content
            _this.total = resp.data.totalElements
          }
        )
      }
    },
    created() {
      const _this = this
      axios.get('http://localhost:9999/findAll/1/3').then(
        function (resp) {
          _this.tableData = resp.data.content
          _this.total = resp.data.totalElements
        }
      )
    },
    data() {
      return {
        total:null,
        tableData: null
      }
    }
  }
</script>

<style scoped>

</style>
